import Vue from 'vue'
import Vuex from 'vuex'

import Encrypt from '@/common/utils/encrypt'

Vue.use(Vuex);

export default new Vuex.Store({
  state:{
    // home被点击的分类
    activeIndex:localStorage.getItem("activeIndex") ? Encrypt.decryptCBC(localStorage.getItem("activeIndex")):0,
    // 用户token
    userToken:localStorage.getItem("utoken") ? localStorage.getItem("utoken") : "",

    // mode 远程连接
    mode:"",

    // 状态颜色
    statusColor:[],

    // 设备列表
    equipmentId:'',


    // 知识库添加类型
    kLabel:'',

    // 菜单list
    menuList:[],

    // RouterList
    RouterList:[]

  },
  mutations:{

    setMenuList(state,list){
      state.menuList = list
    },




    getkLabel(state){
      return Encrypt.decryptCBC(localStorage.getItem("k_label"))
    },
    setkLabel(state,newLabel){
      state.kLabel = newLabel
      localStorage.setItem("k_label",Encrypt.encryptCBC(newLabel))
    },

    setActiveIndex(state,activeIndex){
      state.activeIndex = activeIndex
      localStorage.setItem("activeIndex",Encrypt.encryptCBC(activeIndex))
    },
    getActiveIndex(state){
      return Encrypt.decryptCBC(localStorage.getItem("activeIndex"))
    },


    // 设备id
    setEquipmentId(state,equipmentId){
      state.equipmentId = equipmentId
      sessionStorage.setItem("equipment_id",Encrypt.encryptCBC(equipmentId))
    },
    getEquipmentId(state){
      return Encrypt.decryptCBC(sessionStorage.getItem("equipment_id"))
    },


    // token操作
    setUserToken(state,token){
      state.userToken = token
      localStorage.setItem("utoken",token)
    },
    getUserToken(state){
      return state.userToken
    },

    // mode操作
    setMode(state,mode){
      state.mode = mode
    },
    getMode(state){
      return state.mode
    },
    // 存颜色状态
    setStatusColor(state,ColorArray){
      state.statusColor = ColorArray
    },
    getStatusColor(state,status){
      this.state.statusColor.forEach((item,index,arr) => {
        if(item.status == status){
          return item.displayColor
        }
      })
      return ''
    },
    SET_ROUTERLIST(state,list) {
      state.RouterList = list
    }
  },
  actions:{
    setRouterList({ commit },list){
      commit('SET_ROUTERLIST', list)
    }
  },
})
